# coding: utf-8
# Project：PyCharmMiscProject
# File：字符串作业.py
# Author：liuchuanzhi
# Date ：2025/4/2 20:10
# IDE：PyCharm
import re

def validate_email(email):
    pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    match = re.match(pattern, email)
    if match:
        return '是有效的电子邮件地址'
    else:
        return '不是有效的电子邮件地址'

def classify_email(email):
    pattern1 = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(edu|ac)$'
    pattern2 = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.(com|org|net)$'

    if re.match(pattern1, email):
        return '教育机构'
    elif re.match(pattern2, email):
        return '公司邮箱'
    else:
        return '个人邮箱'

def extract_email_parts(email):
    pattern = r'^([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,})$'
    match = re.match(pattern, email)
    if match:
        return {
            "username": match.group(1),
            "domain": match.group(2),
            "tld": match.group(3)
        }
    return {}

def obfuscate_email(email):
    parts = extract_email_parts(email)
    if not parts:
        return email

    username = parts['username']
    if len(username) >= 2:
        obscured = f"{username[0]}***{username[-1]}"
    else:
        obscured = "***"

    return f"{obscured}@**{parts['domain']}.{parts['tld']}"

email = input("请输入电子邮件地址：")
validation_result = validate_email(email)

if validation_result == '是有效的电子邮件地址':
    category = classify_email(email)
    extracted = extract_email_parts(email)
    obscured = obfuscate_email(email)

    print(f"验证结果：{validation_result}")
    print(f"分类结果：{category}")
    print(f"提取信息：{extracted}")
    print(f"脱敏处理：{obscured}")
else:
    print(validation_result)